/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.xuexiang.xui_lib.component.textview.supertextview;

import ohos.agp.components.AbsButton;
import ohos.agp.components.AttrSet;
import ohos.agp.components.Checkbox;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentState;
import ohos.agp.components.DependentLayout;
import ohos.agp.components.Image;
import ohos.agp.components.Switch;
import ohos.agp.components.Text;
import ohos.agp.components.TextField;
import ohos.agp.components.element.Element;
import ohos.agp.components.element.ElementScatter;
import ohos.agp.components.element.ShapeElement;
import ohos.agp.components.element.StateElement;
import ohos.agp.text.Font;
import ohos.agp.utils.Color;
import ohos.agp.utils.LayoutAlignment;
import ohos.app.Context;

import com.xuexiang.xui_lib.ResourceTable;
import com.xuexiang.xui_lib.component.edittext.ClearEditText;
import com.xuexiang.xui_lib.component.edittext.PasswordEditText;
import com.xuexiang.xui_lib.component.textview.supertextview.adapter.BackgroundElement;
import com.xuexiang.xui_lib.component.textview.supertextview.adapter.ContainsMap;
import com.xuexiang.xui_lib.component.textview.supertextview.adapter.HasTypeface;
import com.xuexiang.xui_lib.component.textview.supertextview.adapter.OfShapeElement;
import com.xuexiang.xui_lib.component.textview.supertextview.adapter.TypedArray;
import com.xuexiang.xui_lib.util.AttrValue;
import com.xuexiang.xui_lib.util.DisplayUtils;
import com.xuexiang.xui_lib.util.ImageTint;
import com.xuexiang.xui_lib.util.ResUtils;
import com.xuexiang.xui_lib.util.TextUtils;

import static ohos.agp.components.DependentLayout.LayoutConfig.ALIGN_PARENT_BOTTOM;
import static ohos.agp.components.DependentLayout.LayoutConfig.ALIGN_PARENT_END;
import static ohos.agp.components.DependentLayout.LayoutConfig.ALIGN_PARENT_TOP;
import static ohos.agp.components.DependentLayout.LayoutConfig.END_OF;
import static ohos.agp.components.DependentLayout.LayoutConfig.START_OF;
import static ohos.agp.components.DependentLayout.LayoutConfig.TRUE;

/**
 * 打造万能的布局满足市面常见的样式
 *
 * @author xuexiang
 * @since 2019-01-14
 */
public class SuperTextView extends DependentLayout implements HasTypeface {
    private static final int SWITCH_BUTTON_WIDTH_SIZE = 40;
    private static final int SWITCH_BUTTON_HEIGHT_SIZE = 20;
    private static final int GRAVITY_LEFT_CENTER = 0;
    private static final int GRAVITY_CENTER = 1;
    private static final int GRAVITY_RIGHT_CENTER = 2;
    private static final int DEFAULT_GRAVITY = 1;
    private static final int DEFAULT_MAX_EMS = 20;

    /**
     * 分割线的类型
     */
    private static final int NONE = 0;
    private static final int TOP = 1;
    private static final int BOTTOM = 2;
    private static final int BOTH = 3;
    private static final int DEFAULT_DIVIDER = BOTTOM;

    /**
     * 输入框
     */
    private static final int TYPE_NONE = 0;
    private static final int TYPE_CLEAR = 1;
    private static final int TYPE_PASSWORD = 2;

    private static final ContainsMap<Integer> GRAVITY =
        new ContainsMap.Builder<>(3, DEFAULT_GRAVITY)
            .put("left_center", GRAVITY_LEFT_CENTER)
            .put("center", GRAVITY_CENTER)
            .put("right_center", GRAVITY_RIGHT_CENTER)
            .build();

    private static final ContainsMap<Integer> DIVIDER_LINE_TYPE =
        new ContainsMap.Builder<>(4, DEFAULT_DIVIDER)
            .put("none", 0)
            .put("top", 1)
            .put("bottom", 2)
            .put("both", 3)
            .build();

    private static final ContainsMap<Integer> RIGHT_VIEW_TYPE =
        new ContainsMap.Builder<Integer>(2, -1)
            .put("checkbox", 0)
            .put("switchBtn", 1)
            .build();

    private static final ContainsMap<Integer> EDITTEXT_BUTTON_TYPE =
        new ContainsMap.Builder<>(3, 0)
            .put("none", 0)
            .put("clear", 1)
            .put("password", 2)
            .build();

    private Context mContext;
    private BaseTextView mLeftView, mCenterView, mRightView;
    private LayoutConfig mLeftBaseViewParams, mCenterBaseViewParams, mRightBaseViewParams;

    private Image mLeftIconIV, mRightIconIV;
    private LayoutConfig mLeftImgParams, mRightImgParams;

    /**
     * 左边图标资源
     */
    private Element mLeftIconRes;
    /**
     * 左边图标的宽
     */
    private int mLeftIconWidth;
    /**
     * 左边图标的高
     */
    private int mLeftIconHeight;
    /**
     * 左边图标的左边距
     */
    private int mLeftIconMarginLeft;
    private Color mLeftIconTint;
    private int mLeftIconPadding;
    /**
     * 右边图标资源
     */
    private Element mRightIconRes;
    /**
     * 右边图标的宽
     */
    private int mRightIconWidth;
    /**
     * 右边图标的高
     */
    private int mRightIconHeight;
    /**
     * 右边图标的右边距
     */
    private int mRightIconMarginRight;
    private Color mRightIconTint;
    private int mRightIconPadding;
    /**
     * 文字默认颜色
     */
    private Color mDefaultTextColor;
    /**
     * 默认字体大小
     */
    private int mDefaultTextSize;
    /**
     * 默认文字的最大字符数
     */
    private int mDefaultMaxEms;
    /**
     * 默认间距
     */
    private int mDefaultMargin;

    private String mLeftTextString;
    private String mLeftTopTextString;
    private String mLeftBottomTextString;

    private String mRightTextString;
    private String mRightTopTextString;
    private String mRightBottomTextString;

    private String mCenterTextString;
    private String mCenterTopTextString;
    private String mCenterBottomTextString;

    private Color mLeftTextColor;
    private Color mLeftTopTextColor;
    private Color mLeftBottomTextColor;

    private Color mCenterTextColor;
    private Color mCenterTopTextColor;
    private Color mCenterBottomTextColor;

    private Color mRightTextColor;
    private Color mRightTopTextColor;
    private Color mRightBottomTextColor;

    private int mLeftTextSize;
    private int mLeftTopTextSize;
    private int mLeftBottomTextSize;

    private int mRightTextSize;
    private int mRightTopTextSize;
    private int mRightBottomTextSize;

    private int mCenterTextSize;
    private int mCenterTopTextSize;
    private int mCenterBottomTextSize;

    private int mLeftTopLines;
    private int mLeftLines;
    private int mLeftBottomLines;

    private int mCenterTopLines;
    private int mCenterLines;
    private int mCenterBottomLines;

    private int mRightTopLines;
    private int mRightLines;
    private int mRightBottomLines;

    private int mLeftTopMaxEms;
    private int mLeftMaxEms;
    private int mLeftBottomMaxEms;

    private int mCenterTopMaxEms;
    private int mCenterMaxEms;
    private int mCenterBottomMaxEms;

    private int mRightTopMaxEms;
    private int mRightMaxEms;
    private int mRightBottomMaxEms;

    private boolean mLeftTopTextBold;
    private boolean mLeftTextBold;
    private boolean mLeftBottomTextBold;

    private boolean mCenterTopTextBold;
    private boolean mCenterTextBold;
    private boolean mCenterBottomTextBold;

    private boolean mRightTopTextBold;
    private boolean mRightTextBold;
    private boolean mRightBottomTextBold;

    private Element mLeftTextBackground;
    private Element mCenterTextBackground;
    private Element mRightTextBackground;

    private Element mLeftTvElementLeft;
    private Element mLeftTvElementRight;

    private Element mCenterTvElementLeft;
    private Element mCenterTvElementRight;

    private Element mRightTvElementLeft;
    private Element mRightTvElementRight;

    private int mLeftTvElementWidth;
    private int mLeftTvElementHeight;

    private int mCenterTvElementWidth;
    private int mCenterTvElementHeight;

    private int mRightTvElementWidth;
    private int mRightTvElementHeight;

    private int mTextViewElementPadding;

    private int mLeftGravity;
    private int mCenterGravity;
    private int mRightGravity;

    private int mLeftViewWidth;

    private Component mTopDividerLineView, mBottomDividerLineView;

    private LayoutConfig mTopDividerLineParams, mBottomDividerLineParams;
    private int mTopDividerLineMarginLR;
    private int mTopDividerLineMarginLeft;
    private int mTopDividerLineMarginRight;

    private int mBottomDividerLineMarginLR;
    private int mBottomDividerLineMarginLeft;
    private int mBottomDividerLineMarginRight;

    private int mDividerLineType;
    private Color mDividerLineColor;
    private int mDividerLineHeight;

    private int mLeftViewMarginLeft;
    private int mLeftViewMarginRight;

    private int mCenterViewMarginLeft;
    private int mCenterViewMarginRight;

    private int mRightViewMarginLeft;
    private int mRightViewMarginRight;


    private boolean mUseRipple;
    private Element mBackgroundElement;

    private SuperTextView.OnSuperTextViewClickListener mSuperTextViewClickListener;

    private SuperTextView.OnLeftTopTvClickListener mLeftTopTvClickListener;
    private SuperTextView.OnLeftTvClickListener mLeftTvClickListener;
    private SuperTextView.OnLeftBottomTvClickListener mLeftBottomTvClickListener;

    private SuperTextView.OnCenterTopTvClickListener mCenterTopTvClickListener;
    private SuperTextView.OnCenterTvClickListener mCenterTvClickListener;
    private SuperTextView.OnCenterBottomTvClickListener mCenterBottomTvClickListener;

    private SuperTextView.OnRightTopTvClickListener mRightTopTvClickListener;
    private SuperTextView.OnRightTvClickListener mRightTvClickListener;
    private SuperTextView.OnRightBottomTvClickListener mRightBottomTvClickListener;

    private AbsButton.CheckedStateChangedListener mSwitchCheckedChangeListener;
    private AbsButton.CheckedStateChangedListener mCheckBoxCheckedChangeListener;

    private SuperTextView.OnLeftImageViewClickListener mLeftImageClickListener;
    private SuperTextView.OnRightImageViewClickListener mRightImageClickListener;

    private boolean mEnableEdit = false;
    /**
     * 输入框
     */
    private TextField mCenterEditText;
    private int mEditTextWidth = LayoutConfig.MATCH_PARENT;

    /**
     * 编辑输入框类型
     */
    private int mEditTextButtonType = TYPE_CLEAR;
    /**
     * 输入框的背景
     */
    private Element mEditBackground;
    private String mEditTextHint;
    private String mEditTextString;
    private int mEditTextInputType;
    /**
     * 密码输入框文字的样式是否是“*”
     */
    private boolean mIsAsteriskStyle;

    private static final int TYPE_CHECKBOX = 0;
    private static final int TYPE_SWITCH = 1;

    private int mRightViewType;
    /**
     * 右边checkbox
     */
    private Checkbox mRightCheckBox;
    /**
     * checkBox的背景
     */
    private Element mRightCheckBoxBg;
    /**
     * 右边checkBox的右边距
     */
    private int mRightCheckBoxMarginRight;
    /**
     * 是否默认选中
     */
    private boolean mIsChecked;
    /**
     * 中间空间的高度
     */
    private int mCenterSpaceHeight;

    /**
     * 右边switch
     */
    private Switch mRightSwitch;
    private int mRightSwitchMarginRight;
    private boolean mSwitchIsChecked;

    /**
     * Switch开关关闭的文字提示
     */
    private String mSwitchTextOff;
    /**
     * Switch开关打开的文字提示
     */
    private String mSwitchTextOn;
    private int mSwitchMinWidth;
    private int mSwitchPadding;
    private int mThumbTextPadding;
    /**
     * Switch开关的滑块样式
     */
    private Element mSwitchThumbResource;
    /**
     * Switch开关的底层样式
     */
    private Element mSwitchTrackResource;

    //====================一下是shape相关属性==================//

    private Color mDefaultShapeColor;

    private Color mSelectorPressedColor;
    private Color mSelectorNormalColor;

//    private Color mSolidColor;

    private float mCornersRadius;
    private float mCornersTopLeftRadius;
    private float mCornersTopRightRadius;
    private float mCornersBottomLeftRadius;
    private float mCornersBottomRightRadius;

    private int mStrokeWidth;
    private Color mStrokeColor;

    private float mStrokeDashWidth;
    private float mStrokeDashGap;

    private boolean mUseShape;

//    private OfShapeElement mGradientElement;

    public SuperTextView(Context context) {
        this(context, null);
    }

    public SuperTextView(Context context, AttrSet attrSet) {
        this(context, attrSet, null);
    }

    public SuperTextView(Context context, AttrSet attrSet, String styleName) {
        super(context, attrSet, styleName);
        mContext = super.mContext;
        mDefaultTextColor = AttrValue.get(attrSet, "stv_color_common_text",
            ResUtils.getFormatColor(ResourceTable.Color_stv_color_common_text));
        mDefaultTextSize = AttrValue.get(attrSet, "stv_text_size",
            (int) ResUtils.getFloat(ResourceTable.Float_default_stv_text_size));
        mDefaultMaxEms = AttrValue.get(attrSet, "stv_max_ems", DEFAULT_MAX_EMS);
        mDefaultMargin = AttrValue.get(attrSet, "stv_margin",
            (int) ResUtils.getFloat(ResourceTable.Float_default_stv_margin));
        mDefaultShapeColor = AttrValue.get(attrSet, "stv_color_shape",
            ResUtils.getFormatColor(ResourceTable.Color_xui_config_color_white));
        getAttr(attrSet);
        initView();
    }

    private void initView() {
        initSuperTextView();

        initLeftIcon();

        initExtraView();

        initRightIcon();

        initLeftTextView();
        initRightTextView();
        initCenterTextView();

        initDividerLineView();
    }


    private void getAttr(AttrSet attrSet) {
        TypedArray typedArray = new TypedArray(attrSet);

        /////////////////////////////////////////////////
        mLeftTextString = typedArray.getString("sLeftTextString");
        mLeftTopTextString = typedArray.getString("sLeftTopTextString");
        mLeftBottomTextString = typedArray.getString("sLeftBottomTextString");

        mCenterTextString = typedArray.getString("sCenterTextString");
        mCenterTopTextString = typedArray.getString("sCenterTopTextString");
        mCenterBottomTextString = typedArray.getString("sCenterBottomTextString");

        mRightTextString = typedArray.getString("sRightTextString");
        mRightTopTextString = typedArray.getString("sRightTopTextString");
        mRightBottomTextString = typedArray.getString("sRightBottomTextString");

        //////////////////////////////////////////////////

        mLeftTextColor = typedArray.getColor("sLeftTextColor", mDefaultTextColor);
        mLeftTopTextColor = typedArray.getColor("sLeftTopTextColor", mDefaultTextColor);
        mLeftBottomTextColor = typedArray.getColor("sLeftBottomTextColor", mDefaultTextColor);

        mCenterTextColor = typedArray.getColor("sCenterTextColor", mDefaultTextColor);
        mCenterTopTextColor = typedArray.getColor("sCenterTopTextColor", mDefaultTextColor);
        mCenterBottomTextColor = typedArray.getColor("sCenterBottomTextColor", mDefaultTextColor);

        mRightTextColor = typedArray.getColor("sRightTextColor", mDefaultTextColor);
        mRightTopTextColor = typedArray.getColor("sRightTopTextColor", mDefaultTextColor);
        mRightBottomTextColor = typedArray.getColor("sRightBottomTextColor", mDefaultTextColor);

        //////////////////////////////////////////////////


        mLeftTextSize = typedArray.getDimensionPixelSize("sLeftTextSize", mDefaultTextSize);
        mLeftTopTextSize = typedArray.getDimensionPixelSize("sLeftTopTextSize", mDefaultTextSize);
        mLeftBottomTextSize = typedArray.getDimensionPixelSize("sLeftBottomTextSize", mDefaultTextSize);

        mCenterTextSize = typedArray.getDimensionPixelSize("sCenterTextSize", mDefaultTextSize);
        mCenterTopTextSize = typedArray.getDimensionPixelSize("sCenterTopTextSize", mDefaultTextSize);
        mCenterBottomTextSize = typedArray.getDimensionPixelSize("sCenterBottomTextSize", mDefaultTextSize);

        mRightTextSize = typedArray.getDimensionPixelSize("sRightTextSize", mDefaultTextSize);
        mRightTopTextSize = typedArray.getDimensionPixelSize("sRightTopTextSize", mDefaultTextSize);
        mRightBottomTextSize = typedArray.getDimensionPixelSize("sRightBottomTextSize", mDefaultTextSize);

        //////////////////////////////////////////////////
        mLeftTopLines = typedArray.getInt("sLeftTopLines", 1);
        mLeftLines = typedArray.getInt("sLeftLines", 1);
        mLeftBottomLines = typedArray.getInt("sLeftBottomLines", 1);

        mCenterTopLines = typedArray.getInt("sCenterTopLines", 1);
        mCenterLines = typedArray.getInt("sCenterLines", 1);
        mCenterBottomLines = typedArray.getInt("sCenterBottomLines", 1);

        mRightTopLines = typedArray.getInt("sRightTopLines", 1);
        mRightLines = typedArray.getInt("sRightLines", 1);
        mRightBottomLines = typedArray.getInt("sRightBottomLines", 1);

        //////////////////////////////////////////////////

        mLeftTopMaxEms = typedArray.getInt("sLeftTopMaxEms", mDefaultMaxEms);
        mLeftMaxEms = typedArray.getInt("sLeftMaxEms", mDefaultMaxEms);
        mLeftBottomMaxEms = typedArray.getInt("sLeftBottomMaxEms", mDefaultMaxEms);

        mCenterTopMaxEms = typedArray.getInt("sCenterTopMaxEms", mDefaultMaxEms);
        mCenterMaxEms = typedArray.getInt("sCenterMaxEms", mDefaultMaxEms);
        mCenterBottomMaxEms = typedArray.getInt("sCenterBottomMaxEms", mDefaultMaxEms);

        mRightTopMaxEms = typedArray.getInt("sRightTopMaxEms", mDefaultMaxEms);
        mRightMaxEms = typedArray.getInt("sRightMaxEms", mDefaultMaxEms);
        mRightBottomMaxEms = typedArray.getInt("sRightBottomMaxEms", mDefaultMaxEms);

        ////////////////////////////////////////////////
        mLeftGravity = GRAVITY.get(typedArray.getString("sLeftViewGravity"));
        mCenterGravity = GRAVITY.get(typedArray.getString("sCenterViewGravity"));
        mRightGravity = GRAVITY.get(typedArray.getString("sRightViewGravity"));
        ////////////////////////////////////////////////

        mLeftTvElementLeft = typedArray.getElementAttrRes("sLeftTvElementLeft");
        mLeftTvElementRight = typedArray.getElementAttrRes("sLeftTvElementRight");
        mCenterTvElementLeft = typedArray.getElementAttrRes("sCenterTvElementLeft");
        mCenterTvElementRight = typedArray.getElementAttrRes("sCenterTvElementRight");
        mRightTvElementLeft = typedArray.getElementAttrRes("sRightTvElementLeft");
        mRightTvElementRight = typedArray.getElementAttrRes("sRightTvElementRight");

        mTextViewElementPadding = typedArray.getDimensionPixelSize("sTextViewElementPadding", mDefaultMargin);
        ////////////////////////////////////////////////

        mLeftTvElementWidth = typedArray.getDimensionPixelSize("sLeftTvElementWidth", -1);
        mLeftTvElementHeight = typedArray.getDimensionPixelSize("sLeftTvElementHeight", -1);

        mCenterTvElementWidth = typedArray.getDimensionPixelSize("sCenterTvElementWidth", -1);
        mCenterTvElementHeight = typedArray.getDimensionPixelSize("sCenterTvElementHeight", -1);

        mRightTvElementWidth = typedArray.getDimensionPixelSize("sRightTvElementWidth", -1);
        mRightTvElementHeight = typedArray.getDimensionPixelSize("sRightTvElementHeight", -1);

        mLeftViewWidth = typedArray.getDimensionPixelSize("sLeftViewWidth", 0);
        ///////////////////////////////////////////////
        mTopDividerLineMarginLR = typedArray.getDimensionPixelSize("sTopDividerLineMarginLR", 0);
        mTopDividerLineMarginLeft = typedArray.getDimensionPixelSize("sTopDividerLineMarginLeft", 0);
        mTopDividerLineMarginRight = typedArray.getDimensionPixelSize("sTopDividerLineMarginRight", 0);

        mBottomDividerLineMarginLR = typedArray.getDimensionPixelSize("sBottomDividerLineMarginLR", 0);
        mBottomDividerLineMarginLeft = typedArray.getDimensionPixelSize("sBottomDividerLineMarginLeft", 0);
        mBottomDividerLineMarginRight = typedArray.getDimensionPixelSize("sBottomDividerLineMarginRight", 0);
        ///////////////////////////////////////////////
        mDividerLineType = DIVIDER_LINE_TYPE.get(typedArray.getString("sDividerLineType"));
        mDividerLineColor = typedArray.getColor("sDividerLineColor", new Color(0xFFF0F2F4));

        mDividerLineHeight = typedArray.getDimensionPixelSize("sDividerLineHeight", DisplayUtils.vp2px(mContext, 0.5f));
        ////////////////////////////////////////////////
        mLeftViewMarginLeft = typedArray.getDimensionPixelSize("sLeftViewMarginLeft", mDefaultMargin);
        mLeftViewMarginRight = typedArray.getDimensionPixelSize("sLeftViewMarginRight", mDefaultMargin);
        mCenterViewMarginLeft = typedArray.getDimensionPixelSize("sCenterViewMarginLeft", 0);
        mCenterViewMarginRight = typedArray.getDimensionPixelSize("sCenterViewMarginRight", 0);
        mRightViewMarginLeft = typedArray.getDimensionPixelSize("sRightViewMarginLeft", mDefaultMargin);
        mRightViewMarginRight = typedArray.getDimensionPixelSize("sRightViewMarginRight", mDefaultMargin);
        ///////////////////////////////////////////////
        mLeftIconRes = typedArray.getElementAttrRes("sLeftIconRes");

        mLeftIconWidth = typedArray.getDimensionPixelSize("sLeftIconWidth", 0);
        mLeftIconHeight = typedArray.getDimensionPixelSize("sLeftIconHeight", 0);
        mLeftIconMarginLeft = typedArray.getDimensionPixelSize("sLeftIconMarginLeft", mDefaultMargin);
        mLeftIconTint = typedArray.getColorStateList("sLeftIconTint");
        mLeftIconPadding = typedArray.getDimensionPixelSize("sLeftIconPadding", 0);

        mRightIconRes = typedArray.getElementAttrRes("sRightIconRes");
        mRightIconWidth = typedArray.getDimensionPixelSize("sRightIconWidth", 0);
        mRightIconHeight = typedArray.getDimensionPixelSize("sRightIconHeight", 0);
        mRightIconMarginRight = typedArray.getDimensionPixelSize("sRightIconMarginRight", mDefaultMargin);
        mRightIconTint = typedArray.getColorStateList("sLeftIconTint");
        mRightIconPadding = typedArray.getDimensionPixelSize("sLeftIconPadding", 0);

        //////////////////////////////////////////////
        mLeftTopTextBold = typedArray.getBoolean("sLeftTopTextIsBold", false);
        mLeftTextBold = typedArray.getBoolean("sLeftTextIsBold", false);
        mLeftBottomTextBold = typedArray.getBoolean("sLeftBottomTextIsBold", false);

        mCenterTopTextBold = typedArray.getBoolean("sCenterTopTextIsBold", false);
        mCenterTextBold = typedArray.getBoolean("sCenterTextIsBold", false);
        mCenterBottomTextBold = typedArray.getBoolean("sCenterBottomTextIsBold", false);

        mRightTopTextBold = typedArray.getBoolean("sRightTopTextIsBold", false);
        mRightTextBold = typedArray.getBoolean("sRightTextIsBold", false);
        mRightBottomTextBold = typedArray.getBoolean("sRightBottomTextIsBold", false);

        mLeftTextBackground = typedArray.getElementAttrRes("sLeftTextBackground");
        mCenterTextBackground = typedArray.getElementAttrRes("sCenterTextBackground");
        mRightTextBackground = typedArray.getElementAttrRes("sRightTextBackground");

        ////////////////////////////////////////////////////

        mEnableEdit = typedArray.getBoolean("sEnableEdit", mEnableEdit);
        mEditBackground = typedArray.getElementAttrRes("sEditBackGround");

        mEditTextWidth = typedArray.getDimensionPixelSize("sEditTextWidth", mEditTextWidth);
        mEditTextString = typedArray.getString("sEditTextString");
        mEditTextHint = typedArray.getString("sEditTextHint");
        mEditTextInputType = typedArray.getInt("inputType", -1);
        mEditTextButtonType = EDITTEXT_BUTTON_TYPE.get(typedArray.getString("sEditTextButtonType"));
        mIsAsteriskStyle = typedArray.getBoolean("sEditTextIsAsteriskStyle", mIsAsteriskStyle);

        //////////////////////////////////////////////
        mUseRipple = typedArray.getBoolean("sUseRipple", true);
        mBackgroundElement = typedArray.getElementAttrRes("sBackgroundElementRes");
        ///////////////////////////////////////////////
        mRightViewType = RIGHT_VIEW_TYPE.get(typedArray.getString("sRightViewType"));
        ////////////////////////////////////////////////
        mIsChecked = typedArray.getBoolean("sIsChecked", false);
        mRightCheckBoxMarginRight = typedArray.getDimensionPixelSize("sRightCheckBoxMarginRight", mDefaultMargin);
        mRightCheckBoxBg = typedArray.getElementAttrRes("sRightCheckBoxRes");
        //////////////////////////////////////////////////
        mRightSwitchMarginRight = typedArray.getDimensionPixelSize("sRightSwitchMarginRight", mDefaultMargin);
        mSwitchIsChecked = typedArray.getBoolean("sSwitchIsChecked", false);
        mSwitchTextOff = typedArray.getString("sTextOff");
        mSwitchTextOn = typedArray.getString("sTextOn");

        mSwitchMinWidth = typedArray.getDimensionPixelSize("sSwitchMinWidth", 0);
        mSwitchPadding = typedArray.getDimensionPixelSize("sSwitchPadding", 0);
        mThumbTextPadding = typedArray.getDimensionPixelSize("sThumbTextPadding", 0);
        System.out.println("mSwitchThumbResource: start");

        mSwitchTrackResource = typedArray.getElementAttrRes("sTrackResource");
        System.out.println("mSwitchTrackResource:" + mSwitchTrackResource);

        mSwitchThumbResource = typedArray.getElementAttrRes("sThumbResource");
        System.out.println("mSwitchThumbResource:" + mSwitchThumbResource);

        mCenterSpaceHeight = typedArray.getDimensionPixelSize("sCenterSpaceHeight", DisplayUtils.vp2px(mContext, 5));
        ////////////////////////////////////////////////////
        mSelectorPressedColor = typedArray.getColor("sShapeSelectorPressedColor", mDefaultShapeColor);
        mSelectorNormalColor = typedArray.getColor("sShapeSelectorNormalColor", mDefaultShapeColor);

        //mSolidColor = typedArray.getColor("sShapeSolidColor", mDefaultShapeColor);

        mCornersRadius = typedArray.getDimensionPixelSize("sShapeCornersRadius", 0);
        mCornersTopLeftRadius = typedArray.getDimensionPixelSize("sShapeCornersTopLeftRadius", 0);
        mCornersTopRightRadius = typedArray.getDimensionPixelSize("sShapeCornersTopRightRadius", 0);
        mCornersBottomLeftRadius = typedArray.getDimensionPixelSize("sShapeCornersBottomLeftRadius", 0);
        mCornersBottomRightRadius = typedArray.getDimensionPixelSize("sShapeCornersBottomRightRadius", 0);

        mStrokeWidth = typedArray.getDimensionPixelSize("sShapeStrokeWidth", 0);
        mStrokeDashWidth = typedArray.getDimensionPixelSize("sShapeStrokeDashWidth", 0);
        mStrokeDashGap = typedArray.getDimensionPixelSize("sShapeStrokeDashGap", 0);

        mStrokeColor = typedArray.getColor("sShapeStrokeColor", mDefaultShapeColor);

        mUseShape = typedArray.getBoolean("sUseShape", false);
    }

    /**
     * 初始化Params
     *
     * @param params params
     * @return params
     */
    private LayoutConfig getParams(LayoutConfig params) {
        if (params == null) {
            params = new LayoutConfig(LayoutConfig.MATCH_CONTENT, LayoutConfig.MATCH_CONTENT);
        }
        return params;
    }

    private void initSuperTextView() {
        if (mUseRipple) {
            Element parse =
                ElementScatter.getInstance(getContext()).parse(ResourceTable.Graphic_stv_btn_selector_white);
            this.setBackground(parse);
            this.setClickable(true);
        }
        if (mBackgroundElement != null) {
            this.setBackground(mBackgroundElement);
        }
        if (mUseShape) {
            setBackground(getSelector());
        }
    }

    //=================以下是shape相关属性方法================//

    /**
     * 获取设置之后的Selector
     *
     * @return stateListElement
     */
    public Element getSelector() {
        StateElement stateElement = new StateElement();
        stateElement.addState(
            new int[]{ComponentState.COMPONENT_STATE_PRESSED},
            getStateElement(ComponentState.COMPONENT_STATE_PRESSED)
        );
        stateElement.addState(
            new int[]{ComponentState.COMPONENT_STATE_SELECTED},
            getStateElement(ComponentState.COMPONENT_STATE_SELECTED)
        );
        stateElement.addState(
            new int[]{ComponentState.COMPONENT_STATE_EMPTY},
            getStateElement(ComponentState.COMPONENT_STATE_EMPTY)
        );
        return stateElement;
    }

    public OfShapeElement getStateElement(int state) {
        OfShapeElement element = new OfShapeElement();
        element.setShape(ShapeElement.RECTANGLE);
        switch (state) {
            case ComponentState.COMPONENT_STATE_PRESSED:
            case ComponentState.COMPONENT_STATE_DISABLED:
            case ComponentState.COMPONENT_STATE_SELECTED:
                element.setColor(mSelectorPressedColor);
                break;
            default:
                element.setColor(mSelectorNormalColor);
        }
        setBorder(element);
        setRadius(element);

        return element;
    }

    /**
     * 设置边框  宽度  颜色  虚线  间隙
     *
     * @param element element
     */
    private void setBorder(OfShapeElement element) {
        element.setStroke(mStrokeWidth, mStrokeColor, mStrokeDashWidth, mStrokeDashGap);
    }

    /**
     * 只有类型是矩形的时候设置圆角半径才有效
     *
     * @param element element
     */
    private void setRadius(OfShapeElement element) {
        if (mCornersRadius != 0) {
            //设置圆角的半径
            element.setCornerRadius(mCornersRadius);
        } else {
            // 参数分别为左上,左下,右上,右上
            element.setCornerRadius(
                mCornersTopLeftRadius,
                mCornersBottomLeftRadius,
                mCornersTopRightRadius,
                mCornersBottomRightRadius
            );
        }
    }


    /**
     * 初始化左边图标
     */
    private void initLeftIcon() {
        if (mLeftIconIV == null) {
            mLeftIconIV = new Image(mContext);
        }
        mLeftImgParams = new LayoutConfig(LayoutConfig.MATCH_CONTENT, LayoutConfig.MATCH_CONTENT);
        mLeftImgParams.addRule(LayoutConfig.ALIGN_PARENT_START, TRUE);
        mLeftImgParams.addRule(LayoutConfig.VERTICAL_CENTER, TRUE);
        if (mLeftIconHeight != 0 && mLeftIconWidth != 0) {
            mLeftImgParams.width = mLeftIconWidth;
            mLeftImgParams.height = mLeftIconHeight;
        }
        mLeftIconIV.setScaleMode(Image.ScaleMode.ZOOM_CENTER);
        mLeftIconIV.setId(ResourceTable.Id_sLeftImgId);
        mLeftIconIV.setLayoutConfig(mLeftImgParams);
        mLeftIconIV.setPadding(mLeftIconPadding, mLeftIconPadding, mLeftIconPadding, mLeftIconPadding);
        if (mLeftIconRes != null) {
            if (mLeftIconWidth != 0 && mLeftIconHeight != 0) {
                mLeftIconRes.setBounds(0, 0, mLeftIconWidth, mLeftIconHeight);
            }
            if (mLeftIconTint != null) {
                mLeftIconRes = ImageTint.getTintElement(mLeftIconRes, mLeftIconTint.getValue());
            }
            mLeftIconIV.setImageElement(mLeftIconRes);
            mLeftIconIV.setMarginLeft(mLeftIconMarginLeft);
        }
        addComponent(mLeftIconIV);
    }

    /**
     * 初始化右边图标
     */
    private void initRightIcon() {
        if (mRightIconIV == null) {
            mRightIconIV = new Image(mContext);
        }
        mRightImgParams = new LayoutConfig(LayoutConfig.MATCH_CONTENT, LayoutConfig.MATCH_CONTENT);
        mRightImgParams.addRule(LayoutConfig.VERTICAL_CENTER, TRUE);

        switch (mRightViewType) {
            case TYPE_CHECKBOX:
                mRightImgParams.addRule(START_OF, ResourceTable.Id_sRightCheckBoxId);
                break;
            case TYPE_SWITCH:
                mRightImgParams.addRule(START_OF, ResourceTable.Id_sRightSwitchId);
                break;
            default:
                mRightImgParams.addRule(ALIGN_PARENT_END, TRUE);
        }

        if (mRightIconHeight != 0 && mRightIconWidth != 0) {
            mRightImgParams.width = mRightIconWidth;
            mRightImgParams.height = mRightIconHeight;
        }

        mRightIconIV.setScaleMode(Image.ScaleMode.CLIP_CENTER);
        mRightIconIV.setId(ResourceTable.Id_sRightImgId);
        mRightIconIV.setLayoutConfig(mRightImgParams);
        mRightIconIV.setPadding(mRightIconPadding, mRightIconPadding, mRightIconPadding, mRightIconPadding);
        if (mRightIconRes != null) {
            mRightImgParams.setMargins(0, 0, mRightIconMarginRight, 0);
            mRightIconIV.setMarginRight(mRightIconMarginRight);
            if (mRightIconHeight != 0 && mRightIconWidth != 0) {
                mRightIconRes.setBounds(0, 0, mRightIconWidth, mRightIconHeight);
            }
            if (mRightIconTint != null) {
                mRightIconRes = ImageTint.getTintElement(mRightIconRes, mRightIconTint.getValue());
            }
            mRightIconIV.setImageElement(mRightIconRes);
        }
        addComponent(mRightIconIV);
    }

    /**
     * 初始化LeftTextView
     */
    private void initLeftTextView() {
        if (mLeftView == null) {
            mLeftView = initBaseView(ResourceTable.Id_sLeftViewId);
        }
        mLeftBaseViewParams = getParams(mLeftBaseViewParams);
        mLeftBaseViewParams.addRule(END_OF, ResourceTable.Id_sLeftImgId);
        mLeftBaseViewParams.addRule(LayoutConfig.VERTICAL_CENTER, TRUE);
        if (mLeftViewWidth != 0) {
            mLeftBaseViewParams.width = mLeftViewWidth;
        }
        mLeftBaseViewParams.setMargins(mLeftViewMarginLeft, 0, mLeftViewMarginRight, 0);

        mLeftView.setLayoutConfig(mLeftBaseViewParams);
        mLeftView.setCenterSpaceHeight(mCenterSpaceHeight);
        setDefaultColor(mLeftView, mLeftTopTextColor, mLeftTextColor, mLeftBottomTextColor);
        setDefaultSize(mLeftView, mLeftTopTextSize, mLeftTextSize, mLeftBottomTextSize);
        setDefaultLines(mLeftView, mLeftTopLines, mLeftLines, mLeftBottomLines);
        setDefaultMaxEms(mLeftView, mLeftTopMaxEms, mLeftMaxEms, mLeftBottomMaxEms);
        setDefaultTextIsBold(mLeftView, mLeftTopTextBold, mLeftTextBold, mLeftBottomTextBold);
        setDefaultGravity(mLeftView, mLeftGravity);
        setDefaultElement(mLeftView.getCenterTextView(), mLeftTvElementLeft, mLeftTvElementRight,
            mTextViewElementPadding, mLeftTvElementWidth, mLeftTvElementHeight);
        setDefaultBackground(mLeftView.getCenterTextView(), mLeftTextBackground);
        setDefaultString(mLeftView, mLeftTopTextString, mLeftTextString, mLeftBottomTextString);
        addComponent(mLeftView);
    }


    /**
     * 初始化CenterTextView
     */
    private void initCenterTextView() {
        if (mEnableEdit) {
            if (mCenterEditText == null) {
                if (mEditTextButtonType == TYPE_NONE) {
                    mCenterEditText = new TextField(mContext);
                } else if (mEditTextButtonType == TYPE_CLEAR) {
                    mCenterEditText = new ClearEditText(mContext);
                } else if (mEditTextButtonType == TYPE_PASSWORD) {
                    mCenterEditText = new PasswordEditText(mContext);
                    // ((PasswordEditText) mCenterEditText).setIsAsteriskStyle(mIsAsteriskStyle);
                }
            }
            /**
             * 输入框布局参数
             */
            LayoutConfig mCenterEditTextParams = new LayoutConfig(mEditTextWidth, LayoutConfig.MATCH_CONTENT);

            mCenterEditTextParams.addRule(LayoutConfig.CENTER_IN_PARENT, TRUE);
            mCenterEditTextParams.addRule(LayoutConfig.VERTICAL_CENTER, TRUE);
            if (mCenterGravity != GRAVITY_CENTER) {
                mCenterEditTextParams.addRule(END_OF, ResourceTable.Id_sLeftViewId);
            }
            mCenterEditTextParams.setMargins(mCenterViewMarginLeft, 0, mCenterViewMarginRight, 0);
            mCenterEditTextParams.setMarginLeft(mCenterViewMarginLeft);
            mCenterEditTextParams.setMarginRight(mCenterViewMarginRight);
            mCenterEditText.setId(ResourceTable.Id_sCenterEditTextId);
            mCenterEditText.setLayoutConfig(mCenterEditTextParams);

            if (mEditBackground != null) {
                mCenterEditText.setBackground(mEditBackground);
            } else {
                mCenterEditText.setBackground(new BackgroundElement(ResUtils.getColor(ResourceTable.Color_xui_config_color_transparent)));
            }
            mCenterEditText.setTextColor(mCenterTextColor);
            mCenterEditText.setTextSize(mCenterTextSize, Text.TextSizeType.PX);
            mCenterEditText.setMaxTextLines(mCenterLines);
            mCenterEditText.setText(mEditTextString);
            mCenterEditText.setHint(mEditTextHint);
            if (mEditTextInputType != -1) {
                mCenterEditText.setTextInputType(mEditTextInputType);
            }
            addComponent(mCenterEditText);
        } else {
            if (mCenterView == null) {
                mCenterView = initBaseView(ResourceTable.Id_sCenterViewId);
            }
            mCenterBaseViewParams = getParams(mCenterBaseViewParams);
            mCenterBaseViewParams.addRule(LayoutConfig.CENTER_IN_PARENT, TRUE);
            mCenterBaseViewParams.addRule(LayoutConfig.VERTICAL_CENTER, TRUE);

            //默认情况下  中间的View整体剧中显示，设置左对齐或者右对齐的话使用下边属性
            if (mCenterGravity != GRAVITY_CENTER) {
                try {
                    mCenterBaseViewParams.addRule(END_OF, ResourceTable.Id_sLeftViewId);
                } catch (Throwable e) {
                    e.printStackTrace();
                }
            }

            mCenterBaseViewParams.setMargins(mCenterViewMarginLeft, 0, mCenterViewMarginRight, 0);
            mCenterBaseViewParams.setMarginLeft(mCenterViewMarginLeft);
            mCenterBaseViewParams.setMarginRight(mCenterViewMarginRight);
            mCenterView.setLayoutConfig(mCenterBaseViewParams);
            mCenterView.setCenterSpaceHeight(mCenterSpaceHeight);

            setDefaultColor(mCenterView, mCenterTopTextColor, mCenterTextColor, mCenterBottomTextColor);
            setDefaultSize(mCenterView, mCenterTopTextSize, mCenterTextSize, mCenterBottomTextSize);
            setDefaultLines(mCenterView, mCenterTopLines, mCenterLines, mCenterBottomLines);
            setDefaultMaxEms(mCenterView, mCenterTopMaxEms, mCenterMaxEms, mCenterBottomMaxEms);
            setDefaultTextIsBold(mCenterView, mCenterTopTextBold, mCenterTextBold, mCenterBottomTextBold);
            setDefaultGravity(mCenterView, mCenterGravity);
            setDefaultElement(mCenterView.getCenterTextView(), mCenterTvElementLeft, mCenterTvElementRight,
                mTextViewElementPadding, mCenterTvElementWidth, mCenterTvElementHeight);
            setDefaultBackground(mCenterView.getCenterTextView(), mCenterTextBackground);
            setDefaultString(mCenterView, mCenterTopTextString, mCenterTextString, mCenterBottomTextString);

            addComponent(mCenterView);
        }
    }

    /**
     * 初始化RightTextView
     */
    private void initRightTextView() {
        if (mRightView == null) {
            mRightView = initBaseView(ResourceTable.Id_sRightViewId);
        }
        mRightBaseViewParams = getParams(mRightBaseViewParams);
        mRightBaseViewParams.addRule(LayoutConfig.VERTICAL_CENTER, TRUE);

        mRightBaseViewParams.addRule(START_OF, ResourceTable.Id_sRightImgId);
        mRightBaseViewParams.setMargins(mRightViewMarginLeft, 0, mRightViewMarginRight, 0);
        mRightView.setLayoutConfig(mRightBaseViewParams);
        mRightView.setCenterSpaceHeight(mCenterSpaceHeight);

        setDefaultColor(mRightView, mRightTopTextColor, mRightTextColor, mRightBottomTextColor);
        setDefaultSize(mRightView, mRightTopTextSize, mRightTextSize, mRightBottomTextSize);
        setDefaultLines(mRightView, mRightTopLines, mRightLines, mRightBottomLines);
        setDefaultMaxEms(mRightView, mRightTopMaxEms, mRightMaxEms, mRightBottomMaxEms);
        setDefaultTextIsBold(mRightView, mRightTopTextBold, mRightTextBold, mRightBottomTextBold);
        setDefaultGravity(mRightView, mRightGravity);
        setDefaultElement(mRightView.getCenterTextView(), mRightTvElementLeft, mRightTvElementRight,
            mTextViewElementPadding, mRightTvElementWidth, mRightTvElementHeight);
        setDefaultBackground(mRightView.getCenterTextView(), mRightTextBackground);
        setDefaultString(mRightView, mRightTopTextString, mRightTextString, mRightBottomTextString);

        addComponent(mRightView);
    }

    /**
     * 初始化拓展控件
     */
    private void initExtraView() {
        switch (mRightViewType) {
            case TYPE_CHECKBOX:
                initRightCheckBox();
                break;
            case TYPE_SWITCH:
                initRightSwitch();
                break;
            default:
                break;
        }
    }

    /**
     * 初始化RightCheckBox
     */
    private void initRightCheckBox() {
        if (mRightCheckBox == null) {
            mRightCheckBox = new Checkbox(mContext);
        }
        // 右边checkbox
        LayoutConfig mRightCheckBoxParams = new LayoutConfig(LayoutConfig.MATCH_CONTENT, LayoutConfig.MATCH_CONTENT);
        mRightCheckBoxParams.addRule(ALIGN_PARENT_END, TRUE);
        mRightCheckBoxParams.addRule(LayoutConfig.VERTICAL_CENTER, TRUE);
        mRightCheckBoxParams.setMargins(0, 0, mRightCheckBoxMarginRight, 0);
        mRightCheckBox.setId(ResourceTable.Id_sRightCheckBoxId);
        mRightCheckBox.setLayoutConfig(mRightCheckBoxParams);
        if (mRightCheckBoxBg != null) {
            // mRightCheckBox.setTextAlignment(CENTER_IN_PARENT);
            mRightCheckBox.setButtonElement(mRightCheckBoxBg);
        }
        mRightCheckBox.setChecked(mIsChecked);
        mRightCheckBox.setCheckedStateChangedListener(mCheckBoxCheckedChangeListener);
        addComponent(mRightCheckBox);
    }

    /**
     * 初始化RightSwitch
     */
    private void initRightSwitch() {
        if (mRightSwitch == null) {
            mRightSwitch = new Switch(mContext);
        }
        LayoutConfig mRightSwitchParams = new LayoutConfig(DisplayUtils.vp2px(getContext(), SWITCH_BUTTON_WIDTH_SIZE),
            DisplayUtils.vp2px(getContext(), SWITCH_BUTTON_HEIGHT_SIZE));
        mRightSwitchParams.addRule(ALIGN_PARENT_END, TRUE);
        mRightSwitchParams.addRule(LayoutConfig.VERTICAL_CENTER, TRUE);
        mRightSwitchParams.setMargins(0, 0, mRightSwitchMarginRight, 0);
        mRightSwitch.setId(ResourceTable.Id_sRightSwitchId);
        mRightSwitch.setLayoutConfig(mRightSwitchParams);
        mRightSwitch.setChecked(mSwitchIsChecked);
        if (!TextUtils.isEmpty(mSwitchTextOff)) {
            mRightSwitch.setStateOffText(mSwitchTextOff);
        }
        if (!TextUtils.isEmpty(mSwitchTextOn)) {
            mRightSwitch.setStateOffText(mSwitchTextOn);
        }
        if (mSwitchMinWidth != 0) {
            mRightSwitch.setMinWidth(mSwitchMinWidth);
        }
        if (mSwitchPadding != 0) {
            mRightSwitch.setPadding(mSwitchPadding, mSwitchPadding, mSwitchPadding, mSwitchPadding);
        }
        if (mSwitchThumbResource != null) {
            mRightSwitch.setThumbElement(mSwitchThumbResource);
        }
        if (mSwitchThumbResource != null) {
            mRightSwitch.setTrackElement(mSwitchTrackResource);
        }
        if (mThumbTextPadding != 0) {
            mRightSwitch.setThumbPadding(mThumbTextPadding, mThumbTextPadding);
        }
        mRightSwitch.setCheckedStateChangedListener(mSwitchCheckedChangeListener);
        addComponent(mRightSwitch);
    }

    /////////////////////////////////////默认属性设置----begin/////////////////////////////////

    /**
     * 初始化BaseTextView
     *
     * @param id id
     * @return baseTextView
     */
    private BaseTextView initBaseView(int id) {
        BaseTextView baseTextView = new BaseTextView(mContext);
        baseTextView.setId(id);
        return baseTextView;
    }

    /**
     * 设置默认值
     *
     * @param baseTextView baseTextView
     * @param topTextString topTextString
     * @param leftTextString leftTextString
     * @param bottomTextString bottomTextString
     */
    private void setDefaultString(BaseTextView baseTextView, String topTextString, String leftTextString,
                                  String bottomTextString) {
        if (baseTextView != null) {
            baseTextView.setTopTextString(topTextString);
            baseTextView.setCenterTextString(leftTextString);
            baseTextView.setBottomTextString(bottomTextString);
        }
    }

    /**
     * 设置默认
     *
     * @param baseTextView baseTextView
     * @param topTextColor topTextColor
     * @param textColor textColor
     * @param bottomTextColor bottomTextColor
     */
    private void setDefaultColor(BaseTextView baseTextView, Color topTextColor, Color textColor,
                                 Color bottomTextColor) {
        if (baseTextView != null) {
            baseTextView.getTopTextView().setTextColor(topTextColor);
            baseTextView.getCenterTextView().setTextColor(textColor);
            baseTextView.getBottomTextView().setTextColor(bottomTextColor);
        }
    }

    /**
     * 设置默认字体大小
     *
     * @param baseTextView baseTextView
     * @param leftTextSize leftTextSize
     * @param topTextSize topTextSize
     * @param bottomTextSize bottomTextSize
     */
    private void setDefaultSize(BaseTextView baseTextView, int topTextSize, int leftTextSize, int bottomTextSize) {
        if (baseTextView != null) {
            baseTextView.getTopTextView().setTextSize(topTextSize, Text.TextSizeType.PX);
            baseTextView.getCenterTextView().setTextSize(leftTextSize, Text.TextSizeType.PX);
            baseTextView.getBottomTextView().setTextSize(bottomTextSize, Text.TextSizeType.PX);
        }
    }

    /**
     * 设置默认maxEms
     *
     * @param baseTextView baseTextView
     * @param topMaxEms topMaxEms
     * @param centerMaxEms centerMaxEms
     * @param bottomMaxEms bottomMaxEms
     */
    private void setDefaultMaxEms(BaseTextView baseTextView, int topMaxEms, int centerMaxEms, int bottomMaxEms) {
        if (baseTextView != null) {
            baseTextView.setMaxEms(topMaxEms, centerMaxEms, bottomMaxEms);
        }
    }

    /**
     * 设置默认lines
     *
     * @param baseTextView baseTextView
     * @param leftTopLines leftTopLines
     * @param leftLines leftLines
     * @param bottomLines bottomLines
     */
    private void setDefaultLines(BaseTextView baseTextView, int leftTopLines, int leftLines, int bottomLines) {
        if (baseTextView != null) {
            baseTextView.getTopTextView().setMaxTextLines(leftTopLines);
            baseTextView.getCenterTextView().setMaxTextLines(leftLines);
            baseTextView.getBottomTextView().setMaxTextLines(bottomLines);
        }
    }

    /**
     * 设置文字对其方式
     *
     * @param baseTextView baseTextView
     * @param gravity 对其方式
     */
    private void setDefaultGravity(BaseTextView baseTextView, int gravity) {
        if (baseTextView != null) {
            setGravity(baseTextView, gravity);
        }
    }

    /**
     * 文字对其方式
     *
     * @param baseTextView in textView
     * @param gravity 对其方式
     */
    private void setGravity(BaseTextView baseTextView, int gravity) {
        switch (gravity) {
            case GRAVITY_LEFT_CENTER:
                baseTextView.setAlignment(LayoutAlignment.START | LayoutAlignment.VERTICAL_CENTER);
                break;
            case GRAVITY_CENTER:
                baseTextView.setAlignment(LayoutAlignment.CENTER);
                break;
            case GRAVITY_RIGHT_CENTER:
                baseTextView.setAlignment(LayoutAlignment.END | LayoutAlignment.VERTICAL_CENTER);
                break;
            default:
                break;
        }
    }

    /**
     * 设置textView的Element
     *
     * @param textView 对象
     * @param ElementLeft 左边图标
     * @param ElementRight 右边图标
     * @param ElementPadding 图标距离文字的间距
     * @param ElementWidth
     * @param ElementHeight
     */
    public void setDefaultElement(Text textView, Element ElementLeft, Element ElementRight, int ElementPadding,
                                  int ElementWidth, int ElementHeight) {
        if (ElementLeft != null || ElementRight != null) {
            textView.setVisibility(VISIBLE);
        }
        //可以指定Element的宽高
        if (ElementWidth != -1 && ElementHeight != -1) {
            if (ElementLeft != null) {
                ElementLeft.setBounds(0, 0, ElementWidth, ElementHeight);
            }
            if (ElementRight != null) {
                ElementRight.setBounds(0, 0, ElementWidth, ElementHeight);
            }
            textView.setAroundElements(ElementLeft, null, ElementRight, null);
        } else {
            textView.setAroundElementsRelative(ElementLeft, null, ElementRight, null);
        }
        textView.setAroundElementsPadding(ElementPadding);
    }

    /**
     * 设置textView的背景，用户传入Element实现圆角之类的样式
     *
     * @param textView 文本控件
     * @param background 背景
     */
    private void setDefaultBackground(Text textView, Element background) {
        if (background != null) {
            textView.setVisibility(VISIBLE);
            textView.setBackground(background);
        }
    }

    /**
     * 初始化分割线
     */
    private void initDividerLineView() {
        if (!mUseShape) {
            switch (mDividerLineType) {
                case NONE:
                    break;
                case TOP:
                    setTopDividerLineView();
                    break;
                case BOTTOM:
                    setBottomDividerLineView();
                    break;
                case BOTH:
                    setTopDividerLineView();
                    setBottomDividerLineView();
                    break;
                default:
                    break;
            }
        }
    }

    /**
     * 设置上边的分割线
     */
    private void setTopDividerLineView() {
        if (mTopDividerLineMarginLR != 0) {
            initTopDividerLineView(mTopDividerLineMarginLR, mTopDividerLineMarginLR);
        } else {
            initTopDividerLineView(mTopDividerLineMarginLeft, mTopDividerLineMarginRight);
        }
    }

    /**
     * 设置下边的分割线
     */
    private void setBottomDividerLineView() {
        if (mBottomDividerLineMarginLR != 0) {
            initBottomDividerLineView(mBottomDividerLineMarginLR, mBottomDividerLineMarginLR);
        } else {
            initBottomDividerLineView(mBottomDividerLineMarginLeft, mBottomDividerLineMarginRight);
        }
    }

    /**
     * 初始化上边分割线view
     *
     * @param marginStart 起始的间距
     * @param marginEnd 结束的间距
     */
    private void initTopDividerLineView(int marginStart, int marginEnd) {
        if (mTopDividerLineView == null) {
            if (mTopDividerLineParams == null) {
                mTopDividerLineParams = new LayoutConfig(LayoutConfig.MATCH_PARENT, mDividerLineHeight);
            }
            mTopDividerLineParams.addRule(ALIGN_PARENT_TOP, TRUE);
            mTopDividerLineParams.setMarginLeft(marginStart);
            mTopDividerLineParams.setMarginRight(marginEnd);
            mTopDividerLineView = new Component(mContext);
            mTopDividerLineView.setLayoutConfig(mTopDividerLineParams);
            mTopDividerLineView.setBackground(new BackgroundElement(mDividerLineColor));
        }
        addComponent(mTopDividerLineView);
    }

    /**
     * 初始化底部分割线view
     *
     * @param marginStart 起始的间距
     * @param marginEnd 结束的间距
     */
    private void initBottomDividerLineView(int marginStart, int marginEnd) {
        if (mBottomDividerLineView == null) {
            if (mBottomDividerLineParams == null) {
                mBottomDividerLineParams = new LayoutConfig(LayoutConfig.MATCH_PARENT, mDividerLineHeight);
            }
            mBottomDividerLineParams.addRule(ALIGN_PARENT_BOTTOM, TRUE);
            mBottomDividerLineParams.setMarginLeft(marginStart);
            mBottomDividerLineParams.setMarginRight(marginEnd);
            mBottomDividerLineView = new Component(mContext);
            mBottomDividerLineView.setLayoutConfig(mBottomDividerLineParams);
            mBottomDividerLineView.setBackground(new BackgroundElement(mDividerLineColor));
        }
        addComponent(mBottomDividerLineView);
    }

    /**
     * 左边点击事件
     *
     * @param baseTextView 文本控件
     */
    private void setDefaultLeftViewClickListener(final BaseTextView baseTextView) {
        if (baseTextView != null) {
            if (mLeftTopTvClickListener != null) {
                baseTextView.getTopTextView().setClickedListener(new ClickedListener() {
                    @Override
                    public void onClick(Component v) {
                        mLeftTopTvClickListener.onClick(baseTextView.getTopTextView());
                    }
                });
            }
            if (mLeftTvClickListener != null) {
                baseTextView.getCenterTextView().setClickedListener(new ClickedListener() {
                    @Override
                    public void onClick(Component v) {
                        mLeftTvClickListener.onClick(baseTextView.getCenterTextView());
                    }
                });
            }
            if (mLeftBottomTvClickListener != null) {
                baseTextView.getBottomTextView().setClickedListener(new ClickedListener() {
                    @Override
                    public void onClick(Component v) {
                        mLeftBottomTvClickListener.onClick(baseTextView.getBottomTextView());
                    }
                });
            }
        }
    }

    /**
     * 中间点击事件
     *
     * @param baseTextView baseTextView
     */
    private void setDefaultCenterViewClickListener(final BaseTextView baseTextView) {
        if (baseTextView != null) {
            if (mCenterTopTvClickListener != null) {
                baseTextView.getTopTextView().setClickedListener(new ClickedListener() {
                    @Override
                    public void onClick(Component v) {
                        mCenterTopTvClickListener.onClick(baseTextView.getTopTextView());
                    }
                });
            }
            if (mCenterTvClickListener != null) {
                baseTextView.getCenterTextView().setClickedListener(new ClickedListener() {
                    @Override
                    public void onClick(Component v) {
                        mCenterTvClickListener.onClick(baseTextView.getCenterTextView());
                    }
                });
            }
            if (mCenterBottomTvClickListener != null) {
                baseTextView.getBottomTextView().setClickedListener(new ClickedListener() {
                    @Override
                    public void onClick(Component v) {
                        mCenterBottomTvClickListener.onClick(baseTextView.getBottomTextView());
                    }
                });
            }
        }
    }

    /**
     * 右边点击事件
     *
     * @param baseTextView baseTextView
     */
    private void setDefaultRightViewClickListener(final BaseTextView baseTextView) {
        if (baseTextView != null) {
            if (mRightTopTvClickListener != null) {
                baseTextView.getTopTextView().setClickedListener(new ClickedListener() {
                    @Override
                    public void onClick(Component v) {
                        mRightTopTvClickListener.onClick(baseTextView.getTopTextView());
                    }
                });
            }
            if (mRightTvClickListener != null) {
                baseTextView.getCenterTextView().setClickedListener(new ClickedListener() {
                    @Override
                    public void onClick(Component v) {
                        mRightTvClickListener.onClick(baseTextView.getCenterTextView());
                    }
                });
            }
            if (mRightBottomTvClickListener != null) {
                baseTextView.getBottomTextView().setClickedListener(new ClickedListener() {
                    @Override
                    public void onClick(Component v) {
                        mRightBottomTvClickListener.onClick(baseTextView.getBottomTextView());
                    }
                });
            }
        }
    }

    /**
     * 字体是否加粗
     *
     * @param baseTextView baseTextView
     * @param topTextBold 上边字体加粗
     * @param centerTextBold 中间字体加粗
     * @param bottomTextBold 下边字体加粗
     */
    private void setDefaultTextIsBold(BaseTextView baseTextView, boolean topTextBold, boolean centerTextBold,
                                      boolean bottomTextBold) {
        if (baseTextView != null) {
            baseTextView.getTopTextView().setFont(getFont(topTextBold));
            baseTextView.getCenterTextView().setFont(getFont(centerTextBold));
            baseTextView.getBottomTextView().setFont(getFont(bottomTextBold));
        }
    }

    private Font getFont(boolean bold) {
        return bold ? Font.DEFAULT_BOLD : Font.DEFAULT;
    }

    @Override
    public void setTypeface(Font typeface) {
        if (mLeftView != null) {
            mLeftView.setTypeface(typeface);
        }
        if (mCenterView != null) {
            mCenterView.setTypeface(typeface);
        }
        if (mCenterEditText != null) {
            mCenterEditText.setFont(typeface);
        }
        if (mRightView != null) {
            mRightView.setTypeface(typeface);
        }
        if (mCenterView != null) {
            mCenterView.setTypeface(typeface);
        }
    }

    /////////////////////////////////////默认属性设置----end/////////////////////////////////


    /////////////////////////////////////对外暴露的方法---begin/////////////////////////////////

    /**
     * 设置左上字符串
     *
     * @param string 字符串
     * @return 方便链式调用
     */
    public SuperTextView setLeftTopString(String string) {
        if (mLeftView != null) {
            mLeftView.setTopTextString(string);
        }
        return this;
    }

    /**
     * 设置左中字符串
     *
     * @param string 字符串
     * @return 方便链式调用
     */
    public SuperTextView setLeftString(String string) {
        if (mLeftView != null) {
            mLeftView.setCenterTextString(string);
        }
        return this;
    }

    /**
     * 设置左下字符串
     *
     * @param string 字符串
     * @return 方便链式调用
     */
    public SuperTextView setLeftBottomString(String string) {
        if (mLeftView != null) {
            mLeftView.setBottomTextString(string);
        }
        return this;
    }

    /**
     * 设置中上字符串
     *
     * @param string 字符串
     * @return 方便链式调用
     */
    public SuperTextView setCenterTopString(String string) {
        if (mCenterView != null) {
            mCenterView.setTopTextString(string);
        }
        return this;
    }

    /**
     * 设置中间字符串
     *
     * @param string 字符串
     * @return 方便链式调用
     */
    public SuperTextView setCenterString(String string) {
        if (mCenterView != null) {
            mCenterView.setCenterTextString(string);
        }
        return this;
    }

    /**
     * 设置输入框字符串
     *
     * @param string 字符串
     * @return 方便链式调用
     */
    public SuperTextView setCenterEditString(String string) {
        if (mCenterEditText != null) {
            mCenterEditText.setText(string);
        }
        return this;
    }

    /**
     * 设置中下字符串
     *
     * @param string 字符串
     * @return 方便链式调用
     */
    public SuperTextView setCenterBottomString(String string) {
        if (mCenterView != null) {
            mCenterView.setBottomTextString(string);
        }
        return this;
    }

    /**
     * 设置右上字符串
     *
     * @param string 字符串
     * @return 方便链式调用
     */
    public SuperTextView setRightTopString(String string) {
        if (mRightView != null) {
            mRightView.setTopTextString(string);
        }
        return this;
    }

    /**
     * 设置右中字符串
     *
     * @param string 字符串
     * @return 方便链式调用
     */
    public SuperTextView setRightString(String string) {
        if (mRightView != null) {
            mRightView.setCenterTextString(string);
        }
        return this;
    }

    /**
     * 设置右下字符串
     *
     * @param string 字符串
     * @return 方便链式调用
     */
    public SuperTextView setRightBottomString(String string) {
        if (mRightView != null) {
            mRightView.setBottomTextString(string);
        }
        return this;
    }

    /**
     * 设置左上文字颜色
     *
     * @param color 颜色值
     * @return SuperTextView
     */
    public SuperTextView setLeftTopTextColor(Color color) {
        if (mLeftView != null) {
            mLeftView.getTopTextView().setTextColor(color);
        }
        return this;
    }

    /**
     * 设置左中文字颜色
     *
     * @param color 颜色值
     * @return SuperTextView
     */
    public SuperTextView setLeftTextColor(Color color) {
        if (mLeftView != null) {
            mLeftView.getCenterTextView().setTextColor(color);
        }
        return this;
    }

    /**
     * 设置左下文字颜色
     *
     * @param color 颜色值
     * @return SuperTextView
     */
    public SuperTextView setLeftBottomTextColor(Color color) {
        if (mLeftView != null) {
            mLeftView.getBottomTextView().setTextColor(color);
        }
        return this;
    }

    /**
     * 设置中上文字颜色
     *
     * @param color 颜色值
     * @return SuperTextView
     */
    public SuperTextView setCenterTopTextColor(Color color) {
        if (mCenterView != null) {
            mCenterView.getTopTextView().setTextColor(color);
        }
        return this;
    }

    /**
     * 设置中间文字颜色
     *
     * @param color 颜色值
     * @return SuperTextView
     */
    public SuperTextView setCenterTextColor(Color color) {
        if (mCenterView != null) {
            mCenterView.getCenterTextView().setTextColor(color);
        }
        return this;
    }

    /**
     * 设置中下文字颜色
     *
     * @param color 颜色值
     * @return SuperTextView
     */
    public SuperTextView setCenterBottomTextColor(Color color) {
        if (mCenterView != null) {
            mCenterView.getBottomTextView().setTextColor(color);
        }
        return this;
    }

    /**
     * 设置右上文字颜色
     *
     * @param color 颜色值
     * @return SuperTextView
     */
    public SuperTextView setRightTopTextColor(Color color) {
        if (mRightView != null) {
            mRightView.getTopTextView().setTextColor(color);
        }
        return this;
    }

    /**
     * 设置右中文字颜色
     *
     * @param color 颜色值
     * @return SuperTextView
     */
    public SuperTextView setRightTextColor(Color color) {
        if (mRightView != null) {
            mRightView.getCenterTextView().setTextColor(color);
        }
        return this;
    }

    /**
     * 设置右下文字颜色
     *
     * @param color 颜色值
     * @return SuperTextView
     */
    public SuperTextView setRightBottomTextColor(Color color) {
        if (mRightView != null) {
            mRightView.getBottomTextView().setTextColor(color);
        }
        return this;
    }

    /**
     * 获取左上字符串
     *
     * @return 返回字符串
     */
    public String getLeftTopString() {
        return mLeftView != null ? mLeftView.getTopTextView().getText().trim() : "";
    }

    /**
     * 获取左中字符串
     *
     * @return 返回字符串
     */
    public String getLeftString() {
        return mLeftView != null ? mLeftView.getCenterTextView().getText().trim() : "";
    }

    /**
     * 获取左下字符串
     *
     * @return 返回字符串
     */
    public String getLeftBottomString() {
        return mLeftView != null ? mLeftView.getBottomTextView().getText().trim() : "";
    }

    ////////////////////////////////////////////

    /**
     * 获取中上字符串
     *
     * @return 返回字符串
     */
    public String getCenterTopString() {
        return mCenterView != null ? mCenterView.getTopTextView().getText().trim() : "";
    }

    /**
     * 获取中间字符串
     *
     * @return 返回字符串
     */

    public String getCenterString() {
        return mCenterView != null ? mCenterView.getCenterTextView().getText().trim() : "";
    }

    /**
     * 获取中下字符串
     *
     * @return 返回字符串
     */
    public String getCenterBottomString() {
        return mCenterView != null ? mCenterView.getBottomTextView().getText().trim() : "";
    }

    /**
     * 获取右上字符串
     *
     * @return 返回字符串
     */
    public String getRightTopString() {
        return mRightView != null ? mRightView.getTopTextView().getText().trim() : "";
    }

    /**
     * 获取右中字符串
     *
     * @return 返回字符串
     */
    public String getRightString() {
        return mRightView != null ? mRightView.getCenterTextView().getText().trim() : "";
    }

    /**
     * 获取右下字符串
     *
     * @return 返回字符串
     */
    public String getRightBottomString() {
        return mRightView != null ? mRightView.getBottomTextView().getText().trim() : "";
    }

    /**
     * 获取左边ImageView
     *
     * @return ImageView
     */
    public Image getLeftIconIV() {
        mLeftImgParams.setMargins(mLeftIconMarginLeft, 0, 0, 0);
        mLeftImgParams.setMarginLeft(mLeftIconMarginLeft);
        return mLeftIconIV;
    }

    /**
     * 获取右边ImageView
     *
     * @return ImageView
     */
    public Image getRightIconIV() {
        mRightImgParams.setMargins(0, 0, mRightIconMarginRight, 0);
        mLeftImgParams.setMarginRight(mRightIconMarginRight);
        return mRightIconIV;
    }

    /**
     * 设置CheckBox是否选中
     *
     * @param isChecked 是否选中
     * @return 返回值
     */
    public SuperTextView setCheckBoxChecked(boolean isChecked) {
        setCheckBoxChecked(isChecked, true);
        return this;
    }

    /**
     * 设置CheckBox是否选中
     *
     * @param isChecked 是否选中
     * @param isSilent 是否不触发回调
     * @return 返回值
     */
    public SuperTextView setCheckBoxChecked(boolean isChecked, boolean isSilent) {
        mIsChecked = isChecked;
        if (mRightCheckBox != null) {
            if (isSilent) {
                mRightCheckBox.setCheckedStateChangedListener(null);
                mRightCheckBox.setChecked(isChecked);
                mRightCheckBox.setCheckedStateChangedListener(mCheckBoxCheckedChangeListener);
            } else {
                mRightCheckBox.setChecked(isChecked);
            }
        }
        return this;
    }

    /**
     * 设置checkbox的背景图
     *
     * @param Element Element对象
     * @return 返回对象
     */
    public SuperTextView setCheckBoxBackground(Element Element) {
        mRightCheckBoxBg = Element;
        if (mRightCheckBox != null) {
            mRightCheckBox.setBackground(Element);
        }
        return this;
    }

    /**
     * 获取checkbox状态
     *
     * @return 返回选择框当前选中状态
     */
    public boolean getCheckBoxIsChecked() {
        boolean isChecked = false;
        if (mRightCheckBox != null) {
            isChecked = mRightCheckBox.isChecked();
        }
        return isChecked;
    }

    /**
     * 设置Switch是否选中
     *
     * @param isChecked Switch是否选中
     * @return 返回值
     */
    public SuperTextView setSwitchIsChecked(boolean isChecked) {
        setSwitchIsChecked(isChecked, true);
        return this;
    }

    /**
     * 设置Switch是否选中
     *
     * @param isChecked Switch是否选中
     * @param isSilent 是否不触发回调
     * @return 返回值
     */
    public SuperTextView setSwitchIsChecked(boolean isChecked, boolean isSilent) {
        mSwitchIsChecked = isChecked;
        if (mRightSwitch != null) {
            if (isSilent) {
                mRightSwitch.setCheckedStateChangedListener(null);
                mRightSwitch.setChecked(isChecked);
                mRightSwitch.setCheckedStateChangedListener(mSwitchCheckedChangeListener);
            } else {
                mRightSwitch.setChecked(isChecked);
            }
        }
        return this;
    }

    /**
     * 获取switch状态
     *
     * @return 返回switch当前选中状态
     */
    public boolean getSwitchIsChecked() {
        boolean isChecked = false;
        if (mRightSwitch != null) {
            isChecked = mRightSwitch.isChecked();
        }
        return isChecked;
    }

    /**
     * 设置左边tv的左侧图片
     *
     * @param elementLeft elementLeft 左边图片资源
     * @return 返回superTextview
     */
    public SuperTextView setLeftTvElementLeft(Element elementLeft) {
        setDefaultElement(mLeftView.getCenterTextView(), elementLeft, null, mTextViewElementPadding,
            mLeftTvElementWidth, mLeftTvElementHeight);
        return this;
    }

    /**
     * 设置左边tv的右侧图片
     *
     * @param elementLeft 右边图片资源
     * @return 返回superTextview
     */
    public SuperTextView setLeftTvElementRight(Element elementLeft) {
        setDefaultElement(mLeftView.getCenterTextView(), null, elementLeft, mTextViewElementPadding,
            mLeftTvElementWidth, mLeftTvElementHeight);
        return this;
    }

    /**
     * 设置中间tv的左侧图片
     *
     * @param elementLeft 左边图片资源
     * @return 返回superTextview
     */
    public SuperTextView setCenterTvElementLeft(Element elementLeft) {
        setDefaultElement(mCenterView.getCenterTextView(), elementLeft, null, mTextViewElementPadding,
            mCenterTvElementWidth, mCenterTvElementHeight);
        return this;
    }

    /**
     * 设置中间tv的右侧图片
     *
     * @param elementLeft 右边图片资源
     * @return 返回superTextview
     */
    public SuperTextView setCenterTvElementRight(Element elementLeft) {
        setDefaultElement(mCenterView.getCenterTextView(), null, elementLeft, mTextViewElementPadding,
            mCenterTvElementWidth, mCenterTvElementHeight);
        return this;
    }

    /**
     * 设置右边tv的左侧图片
     *
     * @param elementLeft 左边图片资源
     * @return 返回superTextview
     */
    public SuperTextView setRightTvElementLeft(Element elementLeft) {
        setDefaultElement(mRightView.getCenterTextView(), elementLeft, null, mTextViewElementPadding,
            mRightTvElementWidth, mRightTvElementHeight);
        return this;
    }

    /**
     * 设置右边tv的右侧图片
     *
     * @param elementLeft 右边图片资源
     * @return 返回superTextview
     */
    public SuperTextView setRightTvElementRight(Element elementLeft) {
        setDefaultElement(mRightView.getCenterTextView(), null, elementLeft, mTextViewElementPadding,
            mRightTvElementWidth, mRightTvElementHeight);
        return this;
    }

    /**
     * 设置左边图标
     *
     * @param leftIcon 左边图标
     * @return 返回对象
     */
    public SuperTextView setLeftIcon(Element leftIcon) {
        if (mLeftIconIV != null) {
            mLeftImgParams.setMargins(mLeftIconMarginLeft, 0, 0, 0);
            mLeftImgParams.setMarginLeft(mLeftIconMarginLeft);
            mLeftIconIV.setImageElement(leftIcon);
        }
        return this;
    }

    /**
     * 设置左边图标
     *
     * @param resId 左边图标资源id
     * @return 返回对象
     */
    public SuperTextView setLeftIcon(int resId) {
        if (mLeftIconIV != null) {
            mLeftImgParams.setMargins(mLeftIconMarginLeft, 0, 0, 0);
            mLeftImgParams.setMarginLeft(mLeftIconMarginLeft);
            mLeftIconIV.setPixelMap(resId);
        }
        return this;
    }

    /**
     * 设置右边图标
     *
     * @param rightIcon 右边图标
     * @return 返回对象
     */
    public SuperTextView setRightIcon(Element rightIcon) {
        if (mRightIconIV != null) {
            mRightImgParams.setMargins(0, 0, mRightIconMarginRight, 0);
            mRightImgParams.setMarginRight(mRightIconMarginRight);
            mRightIconIV.setImageElement(rightIcon);
        }
        return this;
    }

    /**
     * 设置右边图标资源Id
     *
     * @param resId 右边图标
     * @return 返回对象
     */
    public SuperTextView setRightIcon(int resId) {
        if (mRightIconIV != null) {
            mRightImgParams.setMargins(0, 0, mRightIconMarginRight, 0);
            mRightImgParams.setMarginRight(mRightIconMarginRight);
            mRightIconIV.setPixelMap(resId);
            mRightIconIV.setPixelMap(resId);
        }
        return this;
    }

    /**
     * 设置背景
     *
     * @param element 背景资源
     * @return 对象
     */
    public SuperTextView setSBackground(Element element) {
        if (element != null) {
            this.setBackground(element);
        }
        return this;
    }

    /**
     * 获取左上的TextView
     *
     * @return textView
     */
    public Text getLeftTopTextView() {
        Text textView = null;
        if (mLeftView != null) {
            textView = mLeftView.getTopTextView();
        }
        return textView;
    }

    /**
     * 获取左中的TextView
     *
     * @return textView
     */
    public Text getLeftTextView() {
        Text textView = null;
        if (mLeftView != null) {
            textView = mLeftView.getCenterTextView();
        }
        return textView;
    }

    /**
     * 获取左下的TextView
     *
     * @return textView
     */
    public Text getLeftBottomTextView() {
        Text textView = null;
        if (mLeftView != null) {
            textView = mLeftView.getBottomTextView();
        }
        return textView;
    }

    /**
     * 获取中上的TextView
     *
     * @return textView
     */
    public Text getCenterTopTextView() {
        Text textView = null;
        if (mCenterView != null) {
            textView = mCenterView.getTopTextView();
        }
        return textView;
    }

    /**
     * 获取中中的TextView
     *
     * @return textView
     */
    public Text getCenterTextView() {
        Text textView = null;
        if (mCenterView != null) {
            textView = mCenterView.getCenterTextView();
        }
        return textView;
    }

    /**
     * 获取输入框
     *
     * @return 文本输入控件
     */
    public TextField getCenterEditText() {
        return mCenterEditText;
    }

    /**
     * 获取输入框
     *
     * @return 返回输入的文字
     */
    public String getCenterEditValue() {
        if (mCenterEditText != null) {
            return mCenterEditText.getText();
        }
        return "";
    }

    /*   *//**
     * 设置输入框的密码显示样式
     *
     * @param transformationMethod
     * @return
     *//*
    public SuperTextView setPasswordTransformationMethod(PasswordTransformationMethod transformationMethod) {
        if (mCenterEditText != null) {
            if (mCenterEditText instanceof PasswordEditText) {
                ((PasswordEditText) mCenterEditText).setPasswordTransformationMethod(transformationMethod);
            }
        }
        return this;
    }*/

    /**
     * 获取输入框内容是否为空
     *
     * @return true 为空
     */
    public boolean isEditEmpty() {
        if (mCenterEditText != null) {
            return TextUtils.isEmpty(mCenterEditText.getText());
        }
        return true;
    }

    /**
     * 获取输入框内容是否不为空
     *
     * @return false 不为空
     */
    public boolean isEditNotEmpty() {
        if (mCenterEditText != null) {
            return !TextUtils.isEmpty(mCenterEditText.getText());
        }
        return false;
    }

    /**
     * 获取中下的TextView
     *
     * @return textView
     */
    public Text getCenterBottomTextView() {
        Text textView = null;
        if (mCenterView != null) {
            textView = mCenterView.getBottomTextView();
        }
        return textView;
    }

    /**
     * 获取右上的TextView
     *
     * @return textView
     */
    public Text getRightTopTextView() {
        Text textView = null;
        if (mRightView != null) {
            textView = mRightView.getTopTextView();
        }
        return textView;
    }

    /**
     * 获取右中的TextView
     *
     * @return textView
     */
    public Text getRightTextView() {
        Text textView = null;
        if (mRightView != null) {
            textView = mRightView.getCenterTextView();
        }
        return textView;
    }

    /**
     * 获取右下的TextView
     *
     * @return textView
     */
    public Text getRightBottomTextView() {
        Text textView = null;
        if (mRightView != null) {
            textView = mRightView.getBottomTextView();
        }
        return textView;
    }

    /**
     * 设置左边textView文字对齐方式
     *
     * @param gravity 对齐方式
     * @return SuperTextView
     */
    public SuperTextView setLeftTextGravity(int gravity) {
        setTextGravity(mLeftView, gravity);
        return this;
    }

    /**
     * 设置中间textView文字对齐方式
     *
     * @param gravity 对齐方式
     * @return SuperTextView
     */
    public SuperTextView setCenterTextGravity(int gravity) {
        setTextGravity(mCenterView, gravity);
        return this;
    }

    /**
     * 设置右边textView文字对齐方式
     *
     * @param gravity 对齐方式
     * @return SuperTextView
     */
    public SuperTextView setRightTextGravity(int gravity) {
        setTextGravity(mRightView, gravity);
        return this;
    }

    /**
     * 文字对齐方式
     *
     * @param baseTextView view
     * @param gravity 对齐方式
     */
    private void setTextGravity(BaseTextView baseTextView, int gravity) {
        if (baseTextView != null) {
            baseTextView.getCenterTextView().setTextAlignment(gravity);
        }
    }

    /**
     * 设置上边分割线显示状态
     *
     * @param visibility visibility
     * @return superTextView
     */
    public SuperTextView setTopDividerLineVisibility(int visibility) {
        if (mTopDividerLineView == null) {
            setTopDividerLineView();
        }
        mTopDividerLineView.setVisibility(visibility);
        return this;
    }

    /**
     * 设置下边分割线显示状态
     *
     * @param visibility visibility
     * @return superTextView
     */
    public SuperTextView setBottomDividerLineVisibility(int visibility) {
        if (mBottomDividerLineView == null) {
            setBottomDividerLineView();
        }
        mBottomDividerLineView.setVisibility(visibility);
        return this;
    }

    /////////////////////////////////////对外暴露的方法---end/////////////////////////////////

    ////////////////////////////////////////////////////////////////////////////////////

    public interface OnSuperTextViewClickListener {
        void onClick(SuperTextView superTextView);
    }

    public interface OnLeftTopTvClickListener {
        void onClick(Text textView);
    }

    public interface OnLeftTvClickListener {
        void onClick(Text textView);
    }

    public interface OnLeftBottomTvClickListener {
        void onClick(Text textView);
    }

    public interface OnCenterTopTvClickListener {
        void onClick(Text textView);
    }

    public interface OnCenterTvClickListener {
        void onClick(Text textView);
    }

    public interface OnCenterBottomTvClickListener {
        void onClick(Text textView);
    }

    public interface OnRightTopTvClickListener {
        void onClick(Text textView);
    }

    public interface OnRightTvClickListener {
        void onClick(Text textView);
    }

    public interface OnRightBottomTvClickListener {
        void onClick(Text textView);
    }

    public interface OnLeftImageViewClickListener {
        void onClick(Image imageView);
    }

    public interface OnRightImageViewClickListener {
        void onClick(Image imageView);
    }

    /////////////////////////////////////对外暴露的方法---end/////////////////////////////////

    /**
     * 点击事件
     *
     * @param onSuperTextViewClickListener ClickListener
     * @return SuperTextView
     */
    public SuperTextView setOnSuperTextViewClickListener(OnSuperTextViewClickListener onSuperTextViewClickListener) {
        this.mSuperTextViewClickListener = onSuperTextViewClickListener;
        if (mSuperTextViewClickListener != null) {
            this.setClickedListener(new ClickedListener() {
                @Override
                public void onClick(Component component) {
                    mSuperTextViewClickListener.onClick(SuperTextView.this);
                }
            });
        }
        return this;
    }

    public SuperTextView setLeftTopTvClickListener(OnLeftTopTvClickListener leftTopTvClickListener) {
        this.mLeftTopTvClickListener = leftTopTvClickListener;
        setDefaultLeftViewClickListener(mLeftView);
        return this;
    }

    public SuperTextView setLeftTvClickListener(OnLeftTvClickListener leftTvClickListener) {
        this.mLeftTvClickListener = leftTvClickListener;
        setDefaultLeftViewClickListener(mLeftView);
        return this;
    }

    public SuperTextView setLeftBottomTvClickListener(OnLeftBottomTvClickListener leftBottomTvClickListener) {
        this.mLeftBottomTvClickListener = leftBottomTvClickListener;
        setDefaultLeftViewClickListener(mLeftView);
        return this;
    }

    public SuperTextView setCenterTopTvClickListener(OnCenterTopTvClickListener centerTopTvClickListener) {
        this.mCenterTopTvClickListener = centerTopTvClickListener;
        setDefaultCenterViewClickListener(mCenterView);
        return this;
    }

    /**
     * 点击监听
     *
     * @param clickListener clickListener
     * @return return
     */
    public SuperTextView setCenterEditTextClickListener(ClickedListener clickListener) {
        if (mCenterEditText != null) {
            mCenterEditText.setClickedListener(clickListener);
        }
        return this;
    }

    /**
     * 聚焦变化监听
     *
     * @param focusChangeListener focusChangeListener
     * @return return
     */
    public SuperTextView setCenterEditTextFocusChangeListener(Component.FocusChangedListener focusChangeListener) {
        if (mCenterEditText != null && mEditTextButtonType == TYPE_NONE) {
            mCenterEditText.setFocusChangedListener(focusChangeListener);
        }
        return this;
    }

    public SuperTextView setCenterTvClickListener(OnCenterTvClickListener centerTvClickListener) {
        this.mCenterTvClickListener = centerTvClickListener;
        setDefaultCenterViewClickListener(mCenterView);
        return this;
    }

    public SuperTextView setCenterBottomTvClickListener(OnCenterBottomTvClickListener centerBottomTvClickListener) {
        this.mCenterBottomTvClickListener = centerBottomTvClickListener;
        setDefaultCenterViewClickListener(mCenterView);
        return this;
    }

    public SuperTextView setRightTopTvClickListener(OnRightTopTvClickListener rightTopTvClickListener) {
        this.mRightTopTvClickListener = rightTopTvClickListener;
        setDefaultRightViewClickListener(mRightView);
        return this;
    }

    public SuperTextView setRightTvClickListener(OnRightTvClickListener rightTvClickListener) {
        this.mRightTvClickListener = rightTvClickListener;
        setDefaultRightViewClickListener(mRightView);
        return this;
    }

    public SuperTextView setRightBottomTvClickListener(OnRightBottomTvClickListener rightBottomTvClickListener) {
        this.mRightBottomTvClickListener = rightBottomTvClickListener;
        setDefaultRightViewClickListener(mRightView);
        return this;
    }

    public SuperTextView setLeftImageViewClickListener(OnLeftImageViewClickListener listener) {
        mLeftImageClickListener = listener;
        if (mLeftIconIV != null) {
            mLeftIconIV.setClickedListener(new ClickedListener() {
                @Override
                public void onClick(Component component) {
                    mLeftImageClickListener.onClick(mLeftIconIV);
                }
            });
        }
        return this;
    }

    public SuperTextView setRightImageViewClickListener(final OnRightImageViewClickListener listener) {
        this.mRightImageClickListener = listener;
        if (mRightIconIV != null) {
            mRightIconIV.setClickedListener(new ClickedListener() {
                @Override
                public void onClick(Component component) {
                    mRightImageClickListener.onClick(mRightIconIV);
                }
            });
        }
        return this;
    }

    public SuperTextView setSwitchCheckedChangeListener(AbsButton.CheckedStateChangedListener switchCheckedChangeListener) {
        mSwitchCheckedChangeListener = switchCheckedChangeListener;
        if (mRightSwitch != null) {
            mRightSwitch.setCheckedStateChangedListener(mSwitchCheckedChangeListener);
        }
        return this;
    }

    public SuperTextView setCheckBoxCheckedChangeListener(AbsButton.CheckedStateChangedListener checkBoxCheckedChangeListener) {
        mCheckBoxCheckedChangeListener = checkBoxCheckedChangeListener;
        if (mRightCheckBox != null) {
            mRightCheckBox.setCheckedStateChangedListener(mCheckBoxCheckedChangeListener);
        }
        return this;
    }

    /**
     * 设置按下的颜色
     *
     * @param color 颜色
     * @return 对象
     */
    public SuperTextView setShapeSelectorPressedColor(Color color) {
        mSelectorPressedColor = color;
        return this;
    }

    /**
     * 设置正常的颜色
     *
     * @param color 颜色
     * @return 对象
     */
    public SuperTextView setShapeSelectorNormalColor(Color color) {
        mSelectorNormalColor = color;
        return this;
    }

    /**
     * 设置填充的颜色
     *
     * @param color 颜色
     * @return 对象
     */
    public SuperTextView setShapeSolidColor(Color color) {
        //mSolidColor = color;
        return this;
    }

    /**
     * 设置边框宽度
     *
     * @param strokeWidth 边框宽度值
     * @return 对象
     */
    public SuperTextView setShapeStrokeWidth(int strokeWidth) {
        mStrokeWidth = DisplayUtils.vp2px(mContext, strokeWidth);
        return this;
    }

    /**
     * 设置边框颜色
     *
     * @param strokeColor 边框颜色
     * @return 对象
     */
    public SuperTextView setShapeStrokeColor(Color strokeColor) {
        this.mStrokeColor = strokeColor;
        return this;
    }

    /**
     * 设置边框虚线宽度
     *
     * @param strokeDashWidth 边框虚线宽度
     * @return 对象
     */
    public SuperTextView setShapeSrokeDashWidth(float strokeDashWidth) {
        this.mStrokeDashWidth = DisplayUtils.vp2px(mContext, strokeDashWidth);
        return this;
    }

    /**
     * 设置边框虚线间隙
     *
     * @param strokeDashGap 边框虚线间隙值
     * @return 对象
     */
    public SuperTextView setShapeStrokeDashGap(float strokeDashGap) {
        this.mStrokeDashGap = DisplayUtils.vp2px(mContext, strokeDashGap);
        return this;
    }

    /**
     * 设置圆角半径
     *
     * @param radius 半径
     * @return 对象
     */
    public SuperTextView setShapeCornersRadius(float radius) {
        this.mCornersRadius = DisplayUtils.vp2px(mContext, radius);
        return this;
    }

    /**
     * 设置左上圆角半径
     *
     * @param radius 半径
     * @return 对象
     */
    public SuperTextView setShapeCornersTopLeftRadius(float radius) {
        this.mCornersTopLeftRadius = DisplayUtils.vp2px(mContext, radius);
        return this;
    }

    /**
     * 设置右上圆角半径
     *
     * @param radius 半径
     * @return 对象
     */
    public SuperTextView setShapeCornersTopRightRadius(float radius) {
        this.mCornersTopRightRadius = DisplayUtils.vp2px(mContext, radius);
        return this;
    }

    /**
     * 设置左下圆角半径
     *
     * @param radius 半径
     * @return 对象
     */
    public SuperTextView setShapeCornersBottomLeftRadius(float radius) {
        this.mCornersBottomLeftRadius = DisplayUtils.vp2px(mContext, radius);
        return this;
    }

    /**
     * 设置右下圆角半径
     *
     * @param radius 半径
     * @return 对象
     */
    public SuperTextView setShapeCornersBottomRightRadius(float radius) {
        this.mCornersBottomRightRadius = DisplayUtils.vp2px(mContext, radius);
        return this;
    }

    /**
     * 所有与shape相关的属性设置之后调用此方法才生效
     *
     * @return 对象
     */
    public SuperTextView useShape() {
        setBackground(getSelector());
        return this;
    }
}
